let id = new URLSearchParams(location.search).get('id')
console.log(id);

function pinglun() {
    $.ajax({
        type: 'get',
        url: 'http://localhost:8888/api/articles/' + id + '/comments',
        success: function(res) {
            console.log(res);
            if (res.status === 0) {
                let str = ''
                res.data.forEach(item => {
                    str += `<div class="kr_comment_card">
                    <div class="img-wrap">
                      <img src="./uploads/avatar_3.jpg" alt="">
                    </div>
                    <div class="info">
                      <p>${item.uname}  · <span>2020-08-16</span></p>
                      <p>${item.content}</p>
                    </div>
                    <a href="javascript:;" class="like">${item.count}</a>
                  </div>`
                })
                $('#pinglun').append(str)
            }
        }
    })
}
pinglun()
$('#tijiao').submit(function(e) {
    e.preventDefault()
    let data = $(this).serialize()
    $.ajax({
        type: 'post',
        url: 'http://localhost:8888/api/articles/' + id + '/comments',
        data: data,
        success: function(res) {
            if (res.status === 0) {
                layer.msg(res.message)
                $('#tijiao').get(0).reset()
                $('#pinglun').html('')
                pinglun()
            }
        }

    })
})